package com.edu.cmsservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.edu.cmsservice.domain.CrmBanner;
import com.edu.cmsservice.service.CrmBannerService;
import com.edu.commonutils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author ljw
 * @since 2022-09-21
 */
@Api("放映片前台接口")
@RestController
//@CrossOrigin
@RequestMapping("/cmsservice/banner")
public class CrmBannerController {

    @Autowired(required = false)
    private CrmBannerService crmBannerService;

    @ApiOperation(value = "获取首页banner")
    @GetMapping("/getAllBanner")
    @ResponseBody
    @Cacheable(value = "banner", key = "'selectIndexList'")
    public R index() {
        //只要前面两条记录
        QueryWrapper<CrmBanner> wrapper=new QueryWrapper();
        wrapper.orderByDesc("id");//根据id降序
        wrapper.last("limit 2");//有last拼接语句 来得到前面两条数据
        List<CrmBanner> list = crmBannerService.list(wrapper);
        return R.ok().data("list", list);
    }

}

